<%-- 
    Document   : search
    Created on : 7 déc. 2011, 14:10:41
    Author     : MiniK
--%>
<%@page import="fr.annuaireComp.clientUtils.CompetenceModel"%>
<%@page import="fr.DRHclient.models.ProfileSearchModel"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<% ProfileSearchModel searchdata = (ProfileSearchModel) request.getAttribute("searchdata");%>

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <script src="jquery-1.7.1.min.js"></script>
        <title>Rechercher un membre du personnel</title>
    </head>
    <body>
        <h1>Rechercher un membre du personnel</h1>

        <form action="search" method="post" >
            <div id="criteria1" class="criteria">
                <div id="searchparam1">
                    <select class="searchby" name="searchby1" >
                        <option value="idpersonnel" >Identifiant</option>
                        <option value="nom">Nom</option>
                        <option value="prenom">Prenom</option>
                        <option value="bureau">Bureau</option>
                        <option value="sexe">Sexe</option>
                        <option value="dateNaissance">Date de naissance</option>
                        <option value="idfonction">Fonction</option>
                    </select>

                    <input class="value" type="text" name="value1"/>
                    <button class="addcriteria" >Ajouter un critère</button>
                    <button  class="remcriteria" >Supprimer</button>
                </div>

            </div>
            <br/>
            <div> Toutes les compétences proposées sont celles déjà affectées aux personnels.</div>

            <div id="competence1" class="competence" >
                Compétence 
                <select name="compid1">
                    <option></option>
                    <% for (CompetenceModel c : searchdata.availableCompetencesForSearch) {%>
                    <option value="<%= c.id%>" ><%= c.libelle%></option>
                    <% }%>
                </select>
                <br/>
                Années Xp  <select name="anneesxp1"> <option></option><%for (int i = 0; i <= 70; ++i) {%><option><%= i%></option><% }%></select>
                <br/>

                Commentaires : <input name="commentaire1" type="text" value="" />
                <button class="addcomp" >Ajouter une compétence</button>
                <button class="remcomp" >Supprimer</button>
            </div>
            <br/>
            <input type="submit" value="Chercher">
        </form>

        <script type="text/javascript">
            /*
             $(".searchby").live("change", function(){
                   //remove from formular
                        --criteriaId;
                   var selectedSearchBy = $("select option:selected").val();
                   if(selectedSearchBy == "sexe")
                      {
                          $(this).siblings(".value").attr("type")
                       
                      }
                 });
              
               });*/
         
            var criteriaId = 1;
            var compId = 1;
            $("button").live("click", function(event){
                event.preventDefault();
            });
            
            $(".remcomp").live("click", function(){
                //remove from formular
                --compId;
                $(this).parents(".competence").slideUp();
                $(this).parents(".competence").remove(); 
            });
       
            $(".remcriteria").live("click", function(){
                //remove from formular
                --criteriaId;
                $(this).parents(".criteria").slideUp();
                $(this).parents(".criteria").remove(); 
            });
       
       
            $(".addcriteria").live("click", function(){
                //add new  creteria
                insertNewCriterion($(this).parents(".criteria"));
            });
           
            $(".addcomp").live("click", function(){
                //add new  creteria
                insertNewCompetence($(this).parents(".competence"));
            });
           
            function insertNewCompetence(node)
            {
                ++compId;
                var newComp = $("#competence1").clone();
                
                newComp.find('select[name="compid1"]').attr("name","compid"+compId);
                
                newComp.find('select[name="anneesxp1"]').attr("name","anneesxp"+compId);
                
                newComp.find('input[name="commentaire1"]').attr("value","");//Efface l'ancienne value copîée
                newComp.find('input[name="commentaire1"]').attr("name","commentaire"+compId);
                node.after(newComp);
                
            }
         
            function insertNewCriterion(node){
                ++criteriaId;
                var newCriteria = $("#criteria1").clone();
                newCriteria.find('input[name="value1"]').attr("value",""); //Efface l'ancienne value copîée
                newCriteria.find('select').attr("name","searchby"+criteriaId);
                newCriteria.find('input[name="value1"]').attr("name","value"+criteriaId);
                node.after(newCriteria);
                
            }
            
        </script>
    </body>
</html>
